package netTrackerGUI;

import netTracker.NetTracker;
import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.Font;

/**
 * Handles the GUI components of NetTracker. 
 * See NetTracker.java for details.
 * 
 * @author David Cummings
 */

@SuppressWarnings("serial")	// GUI does not need to be serializable.

public class NetTrackerGUI extends JFrame{
	/** Define width and height of window. */
	final static int WIDTH = 800, HEIGHT = 494;
	/** Define width and height of each cell. */
	final static int CELLWIDTH = 66, CELLHEIGHT = 15;
	/** Define default number of tracks and cells. */
	final static int TRACKS = 4;
	final static int CELLS = 32;
	final static int MARGIN = 6;
	/** Define default global font for note names. */
	final static Font NOTE_FONT = new Font("Dialog", Font.PLAIN, 10);
	
	/** The NetTracker for which this class serves as GUI. */
	NetTracker netTracker;
	/** Main panel for displaying everything. */
	JPanel mainPanel;
	/** Panel for song editor. */
	TrackerPanel tracker;
	/** JPanel for menus. */
	MenuPanel menus;
	/** JPanel for chat window. */
	ChatPanel chat;
	
	/** Indicates whether the mouse is being held down.
	 * 	This value is set by individual cells. */
	boolean pressed; 
	
	/**
	 * Constructs the NetTracker GUI.
	 */
	public NetTrackerGUI(){
		setSize(WIDTH,HEIGHT+25);					// Set window size. Add fudge factor for top menubar.
		setTitle("NetTracker");						// Set title.
		setDefaultCloseOperation(EXIT_ON_CLOSE);	// Guarantee program exits.
		
		netTracker = new NetTracker(this, TRACKS, CELLS);	// Instantiate brain of program.
		pressed = false;
		
		/** Initialize panels: */
		mainPanel = new JPanel(new BorderLayout());
		tracker = new TrackerPanel(netTracker, this);
		menus = new MenuPanel(netTracker);
		chat = new ChatPanel(netTracker);
		
		/** Set up layouts: */
		tracker.setLayout(new BoxLayout(tracker, BoxLayout.X_AXIS));
		
		/** Add the panels: */
		mainPanel.add(tracker, BorderLayout.WEST);
		mainPanel.add(menus, BorderLayout.CENTER);
		mainPanel.add(chat, BorderLayout.EAST);
		getContentPane().add(mainPanel);		
		setResizable(false);
		setVisible(true);
	}
	
	/** @return the tracker panel of the GUI. */
	public TrackerPanel getTrackerPanel(){
		return tracker;
	}
	
	/**
	 * 
	 * @param cellX
	 * @param cellY
	 * @return the cell GUI at x,y in the current pattern
	 */
	public CellGUI getCell(int cellX, int cellY){
		return tracker.getCell(cellX, cellY);
	}
	
	public boolean isPressed(){
		return pressed;
	}
	public void setPressed(boolean pressed){
		this.pressed = pressed;
	}
}
